package com.ellwood.copyright.framework.config.mybatis;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.ellwood.copyright.framework.handler.MyMetaObjectHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ProjectName: ell-copyright-pro
 * @PackageName: com.ellwood.copyright.framework.config.mybatis
 * @ClassName: MybatisPlusConfig
 * @Description: // mybatisPlus配置
 * @Author: Ellwood
 * @CreateDate: 2024/11/21 - 14:57
 * @Version: V1.0.0
 */
@Configuration
public class MybatisPlusConfig {

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // TODO 数据权限 后期根据业务再进行处理
        // 分页插件
        interceptor.addInnerInterceptor(getInnerInterceptor());
        // 乐观锁
        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        // 防止全表更新与删除
        interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
        return interceptor;
    }

    /**
     * 分页插件配置
     * @return 返回分页插件
     */
    private PaginationInnerInterceptor getInnerInterceptor() {
        // 分页插件一些其他配置写进来
        return new PaginationInnerInterceptor(DbType.MYSQL);
    }

    /**
     * 自动填充配置
     * @return MyMetaObjectHandler
     */
    @Bean
    public MyMetaObjectHandler myMetaObjectHandler(){
        return new MyMetaObjectHandler();
    }

}
